<!--
 * @Author: your name
 * @Date: 2021-03-15 08:53:56
 * @LastEditTime: 2021-03-15 11:39:18
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \Python自然语言处理课堂案例d:\拓晟教育\课堂demo\vue11\day03\01v-if 使用场景.html
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>vue基础语法03</title>
    <script src="./js/vue.js"></script>
    <link rel="stylesheet" href="css/tab.css" />
  </head>
  <body>
    <div id="app">
      <div class="tab">
        <ul>
          <!--  通过v-on 添加点击事件   需要把当前li 的索引传过去 
      -->
          <li
            :class="defaultIndex==index?'active':'' "
            :key="item.id"
            v-for="(item,index) in list"
            v-on:click="changed(index)"
          >
            {{item.title}}
          </li>
        </ul>
        <div
          :class="defaultIndex==index?'current':'' "
          :key="item.id"
          v-for="(item, index) in list"
        >
          <img :src="item.path" />
        </div>
      </div>
    </div>
    <script>
      new Vue({
        el: "#app",
        data: {
          defaultIndex: 0,
          list: [
            {
              id: 1,
              title: "apple",
              path: "img/apple.png"
            },
            {
              id: 2,
              title: "orange",
              path: "img/orange.png"
            },
            {
              id: 3,
              title: "lemon",
              path: "img/lemon.png"
            }
          ]
        },
        methods: {
          changed: function (idx) {
            // console.log(idx);
            this.defaultIndex = idx;
          }
        }
      });
    </script>
  </body>
</html>
